<template>
  <di style="padding: 20px;width: 80%">
    <h2 style="margin-left: 20px;margin-top: 0px">编辑分类</h2>
    <!--  数据表单  -->
    <el-form :rules="rules" ref="ruleForm" :inline="true" :model="form" style="width: 150%" label-width="100px">
    <el-form-item label="名称" prop="username">
        <el-input v-model="form.name" placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" placeholder="请输入备注"></el-input>
      </el-form-item>
    </el-form>

    <!-- 按键 -->
    <div style="text-align: center; margin-top: 30px">
      <el-button type="primary" @click="save" size="mediu">提交</el-button>
      <!--      <el-button type="danger">取消</el-button>-->
    </div>
  </di>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "EditCategory.vue",
  data() {
    return {
      form: {},
      rules: {
        name: [
          {required : true, message: '请输入分类名称', trigger: 'blur'},
        ]
      }
    }
  },
  created() {
    const id = this.$route.query.id
    request.get("/category/" + id).then(res => {
      this.form = res.data
    })
  },
  methods: {
    save() {
      request.put('/category/update',this.form).then(res => {
        if (res.code === '200') {
          this.$notify.success('更新成功')
          this.$router.push("/categoryList")
        }else {
          this.$notify.error(res.msg)
        }
      })
    }
  }
}
</script>
